package com.kungfuhacking.wristbandpro.location.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.find.bean.ConfirmHistoryEnty;
import com.kungfuhacking.wristbandpro.utils.AbDateUtil;

import java.util.List;

/**
 * Created by Aaron on 17/7/17.
 */

public class ConfirmAdapter extends RecyclerView.Adapter<ConfirmAdapter.MyViewHolder> {

    private Context context;
    private List<ConfirmHistoryEnty> enties;

    public ConfirmAdapter(Context context, List<ConfirmHistoryEnty> enties) {
        this.context = context;
        this.enties = enties;
    }

    public void setEnties(List<ConfirmHistoryEnty> enties) {
        this.enties = enties;
    }

    @Override
    public ConfirmAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ConfirmAdapter.MyViewHolder(
                LayoutInflater.from(context).inflate(R.layout.item_confirm_history, parent,
                        false));
    }

    @Override
    public void onBindViewHolder(ConfirmAdapter.MyViewHolder holder, int position) {
//        holder.phoneNum.setText(enties.get(position).getPhoneNum());
//        holder.time.setText(enties.get(position).getTime());
//        holder.status.setText(enties.get(position).getStatus());

        if (position == 0) {
//            holder.phoneNum.setGravity(Gravity.CENTER);
//            holder.time.setGravity(Gravity.CENTER);
//            holder.status.setGravity(Gravity.CENTER);
            holder.phoneNum.setText("号码");
            holder.time.setText("时间");
            holder.status.setText("状态");
        } else {
            --position;
            holder.phoneNum.setText(enties.get(position).getPhoneNum());
            holder.time.setText(AbDateUtil.getStringByFormat(
                    enties.get(position).getCheckTime(), AbDateUtil.DATEFORMATYMDHM));
            holder.status.setText(enties.get(position).getState_msg());
        }

    }

    @Override
    public int getItemCount() {
        return enties.size() + 1;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView status;
        TextView time;
        TextView phoneNum;

        MyViewHolder(View view) {
            super(view);
            status = (TextView) view.findViewById(R.id.status);
            time = (TextView) view.findViewById(R.id.time);
            phoneNum = (TextView) view.findViewById(R.id.phoneNum);
        }
    }
}